package snake.gameplay;

import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;

public class Snake {

    private List<Position> tailPositions;
    private int snakeLength;
    private Position startPosition;
    //private Position headPosition;
    private int movementDirection = KeyEvent.VK_RIGHT;

    public Snake() {
        this(1, 5, 5);
    }

    public Snake(int snakeLength, int startCoordinateX, int startCoordinateY) {
        this(snakeLength, new Position(startCoordinateX, startCoordinateY));
    }

    public Snake(int snakeLength, Position startPosition) {
        this.startPosition = startPosition;
        this.snakeLength = snakeLength;
        //this.headPosition = startPosition;
        initTailPositions();
    }

    private void initTailPositions() {
        tailPositions = new ArrayList<Position>();
        tailPositions.add(startPosition);
        Position cursor = startPosition;
        for (int i = 1; i < this.snakeLength; i++) {
            tailPositions.add(Position.sumPositions(cursor, new Position(-1, 0)));
        }
    }

    public int getSnakeLength() {
        return snakeLength;
    }

    public void setSnakeLength(int val) {
        this.snakeLength = val;
    }

    public Position getStartPosition() {
        return startPosition;
    }

    public void setStartPosition(Position val) {
        this.startPosition = val;
    }

    public Position getHeadPosition() {
        return tailPositions.get(0);
    }
    
    public void setHeadPosition(Position headPosition){
        this.tailPositions.set(0, headPosition);
    }

    public int getMovementDirection() {
        return movementDirection;
    }

    public void setMovementDirection(int movementDirection) {
        this.movementDirection = movementDirection;
    }

    public List<Position> getTailPositions() {
        return tailPositions;
    }

    public void setTailPositions(List<Position> tailPositions) {
        this.tailPositions = tailPositions;
    }
}
